#pragma once


#include <vector>
#include <map>

typedef std::vector< std::pair<std::string,std::string> > HttpDict;

struct HttpHeader
{
	HttpDict dict;
};

struct HttpRequest
	:public HttpHeader
{
	HttpRequest()
		:port(0)
		,post(false)
		,bProxyMode(true)
	{

	}
	HttpDict dict;
	std::string uri;
	std::string httpVersion;
	std::string uri_host;
	std::string host;
	int port;
	bool post;
	bool bProxyMode;
};



//response
struct HttpResponse
	:public HttpHeader
{
	HttpResponse()
		:headerLength(0)
		,contentLenght(0)
	{

	}
	std::string status;
	size_t headerLength;
	size_t contentLenght;
};

size_t FindParam(const HttpHeader& r, const string& Param);
bool GetHeader(const HttpHeader& r,const string& Param,string& Value);
void SetHeader(HttpHeader& r,const string& Param,const string& Value);

char* FormRequest(const HttpRequest& r);
char* FormResponse(const HttpResponse& r);
bool parseHttpResponse(char *pHdr, size_t hdrLen, HttpResponse& r);
bool parseHttpRequest(char *pHdr, size_t hdrLen, HttpRequest& r);

void* http_alloc(size_t size);
void http_free(void* mem);
char* http_strdup(const char* str);
wchar_t* http_wstrdup(const wchar_t* str);
